package com.wuzheng.wisgo.sanitation.cloud.controller.transfer;

import com.wuzheng.wisgo.sanitation.cloud.model.common.param.DeleteParam;
import com.wuzheng.wisgo.sanitation.cloud.model.transfer.BaTransferRouteCriteria;
import com.wuzheng.wisgo.sanitation.cloud.model.transfer.param.TransferRouteAddParam;
import com.wuzheng.wisgo.sanitation.cloud.paraandgetutil.VehicleException;
import com.wuzheng.wisgo.sanitation.cloud.repository.entity.transfer.TransferRoute;
import com.wuzheng.wisgo.sanitation.cloud.service.transfer.TransferRouteService;
import com.wuzheng.wisgo.sanitation.framework.base.controller.BaseController;
import com.wuzheng.wisgo.sanitation.framework.core.constant.SysRespEnum;
import com.wuzheng.wisgo.sanitation.framework.core.protocol.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author：hoipang
 * @date：Created in 2019-12-06
 * @description：转运路线控制器
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("/transferRoute")
@Api(value = "TransferRouteCtrl", tags = "转运路线接口")
public class TransferRouteCtrl extends BaseController {

    @Autowired
    private TransferRouteService transferRouteService;

    /**
     * 获取转运路线特定信息分页列表
     */
//    @PostMapping(value = "/pageList")
//    @ApiOperation(value = "获取转运路线特定信息分页列表")
//    public Result<List<TransferRouteDTO>> pageList(@RequestBody TransferRouteListParam transferRouteListParam) {
//        return this.success(SysRespEnum.SUCCESS.getMessage(), transferRouteService.pageTransferRouteDTOs(transferRouteListParam));
//    }

    /**
     * 获取车辆信息列表
     */
    @PostMapping(value = "/fetchList")
    @ApiOperation(value = "获取转运路线信息列表")
    @ResponseBody
    public Result<TransferRoute> fetchList(@RequestBody BaTransferRouteCriteria baTransferRouteCriteria) {
        return this.success("查询成功",transferRouteService.selectPage(baTransferRouteCriteria));
    }

    /**
     * 删除转运路线
     */
    @PostMapping(value = "/delete")
    @ApiOperation(value = "删除转运路线(支持批量)")
    public Result<String> delete(@RequestBody DeleteParam deleteParam) {
        transferRouteService.removeTransferRoutes(deleteParam.getIds());
        return this.success(SysRespEnum.SUCCESS.getMessage());
    }

    /**
     * 获取转运路线
     */
//    @GetMapping(value = "/{id}")
//    @ApiOperation(value = "获取转运路线")
//    public Result<TransferRoute> get(@PathVariable("id") Long id) {
//        return this.success(transferRouteService.selectById(id));
//    }

    /**
     * 新增转运路线
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增转运路线")
    public Result<String> add(@RequestBody @Validated TransferRouteAddParam transferRouteAddParam) {
        try {
            transferRouteService.addTransferRoutes(transferRouteAddParam);
        } catch (VehicleException e) {
            e.printStackTrace();
            return this.failure(e.getMessage());
        }
        return this.success("新增成功");
    }

    /**
     * 获取转运路线
     */
    @PostMapping(value = "/getUpdateById")
    @ApiOperation(value = "获取转运路线")
    public Result<TransferRouteAddParam> getUpdateById(@RequestBody String id) {
        TransferRouteAddParam routeAddParam=new TransferRouteAddParam();
        try {
             routeAddParam = transferRouteService.selectTransferRouteById(id);
        } catch (VehicleException e) {
            e.printStackTrace();
            return this.failure(e.getMessage());
        }
        return this.success("获取数据成功",routeAddParam);
    }

    /**
     * 修改转运路线
     */
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改转运路线")
    public Result<String> update(@RequestBody @Validated TransferRouteAddParam transferRouteAddParam) {
        try {
            transferRouteService.updateTransferRoutes(transferRouteAddParam);
        } catch (VehicleException e) {
            e.printStackTrace();
            return this.failure(e.getMessage());
        }
        return this.success("修改成功");
    }
}

